#include <QHeaderView>

#include <QDebug>
#include <QString>
#include <QMap>

#include <QAbstractItemView>

#include <QFileDialog>

#include <QAxObject>
#include <QTableWidgetItem>
#include <QMessageBox>
//#include <QDialogButtonBox>
#include <QDateTime>

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "incomplete_data.h"


//#define DATA_LENGTH 150

// 数据编号的最大值 -- 增加数据时，要修改这个值
int data_number_max;

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{

    ui->setupUi(this);


    init();

    excel_title.append("日期");
    excel_title.append("垃圾处理量");
    excel_title.append("发电量(1#)");
    excel_title.append("发电量(2#)");
    excel_title.append("发电量(合计)");
    excel_title.append("运行小时数");
    excel_title.append("上网电量");
    excel_title.append("厂用电率");
    excel_title.append("蒸汽产生量(1#)");
    excel_title.append("蒸汽产生量(2#)");
    excel_title.append("蒸汽产生量(3#)");
    excel_title.append("蒸汽产生量(合计)");

    excel_title.append("垃圾来源");
    excel_title.append("垃圾种类");
    excel_title.append("车辆信息");
    excel_title.append("称重信息");
    excel_title.append("进场垃圾量");

    excel_title.append("进炉垃圾量(1#)");
    excel_title.append("进炉垃圾量(2#)");
    excel_title.append("进炉垃圾量(3#)");
    excel_title.append("进炉垃圾量(合计)");
    excel_title.append("计量设备定期校验");
    excel_title.append("故障及异常情况记录");
    excel_title.append("垃圾运输车辆不定期抽查");
    excel_title.append("计量设备检查、调整、保养与维修记录是否正常");

    excel_title.append("入场垃圾热值");
    excel_title.append("地磅及时冲洗、是否清洁（拍照）");
    excel_title.append("安全标识、设备是否完好");
    excel_title.append("卸料门及时关闭");
    excel_title.append("垃圾贮坑排风除臭系统正常运行");
    excel_title.append("垃圾池存量");


    excel_title.append("飞灰产生量");
    excel_title.append("飞灰出场量");
    excel_title.append("飞灰处理系统正常运行");
    excel_title.append("配备飞灰稳定化系统（如有）的焚烧厂，飞灰稳定化后的飞灰浸出液污染物浓度限位值");
    excel_title.append("飞灰收集、运送及贮存密闭情况");
    excel_title.append("设备检查、调整、保养与维修记录是否正常");
    excel_title.append("飞灰固化满足GB16889要求");

    excel_title.append("炉渣产生量");
    excel_title.append("现场目视检查渣坑炉渣状况并拍照存证");
    excel_title.append("炉渣产出情况是否正常");
    excel_title.append("热灼减率检测");
    excel_title.append("处理方式");
    excel_title.append("炉渣出场量");
    excel_title.append("检查炉渣的运出或暂存登记");
    excel_title.append("渗滤液产量");
    excel_title.append("垃圾池内渗滤液液位状况");
    excel_title.append("渗滤液导排系统是否正常");
    excel_title.append("浓缩液产量");
    excel_title.append("浓缩液处理方式");
    excel_title.append("设备运转情况是否正常");
    excel_title.append("运营方渗滤液排放水质检测报告审查");
    excel_title.append("出水水质是否达标(COD)");
    excel_title.append("出水水质是否达标(BOD)");
    excel_title.append("出水水质是否达标(氨氮)");
    excel_title.append("出水水质是否达标(PH)");
    excel_title.append("出水水质是否达标(浊度)");

    excel_title.append("消耗品进场量(燃油)");
    excel_title.append("消耗品进场量(石灰)");
    excel_title.append("消耗品进场量(活性炭)");
    excel_title.append("消耗品进场量(氢氧化钠)");
    excel_title.append("消耗品进场量(尿素（氨水）)");
    excel_title.append("消耗品进场量(螯合剂)");
    excel_title.append("消耗品进场量(水泥)");
    excel_title.append("消耗品使用量(柴油)");
    excel_title.append("消耗品使用量(石灰)");
    excel_title.append("消耗品使用量(活性炭)");
    excel_title.append("消耗品使用量(氢氧化钠)");
    excel_title.append("消耗品使用量(尿素（氨水）)");
    excel_title.append("消耗品使用量(螯合剂)");
    excel_title.append("消耗品使用量(水泥)");

    excel_title.append("在线监测系统（CEMS）正常运行");
    excel_title.append("烟气净化系统正常运行");
    excel_title.append("排放烟气中不合格小时数");
    excel_title.append("排放烟气中污染物含量1#NID(NOx)");
    excel_title.append("排放烟气中污染物含量1#NID(SO2)");
    excel_title.append("排放烟气中污染物含量1#NID(Dust)");
    excel_title.append("排放烟气中污染物含量1#NID(HCl)");
    excel_title.append("排放烟气中污染物含量1#NID(CO)");
    excel_title.append("排放烟气中污染物含量1#NID(重金属)");
    excel_title.append("排放烟气中污染物含量1#NID(二恶英)");

    excel_title.append("是否正常运行1#");
    excel_title.append("是否正常运行2#");
    excel_title.append("起炉停炉是否按规章正确操作");
    excel_title.append("出口氧气含量在6%-10%以外的小时数");
    excel_title.append("炉膛压力为正压的小时数");
    excel_title.append("烟气停留时间");
    excel_title.append("炉膛温度低于850°小时数");

    excel_title.append("车辆车容车貌");
    excel_title.append("消杀灭蝇效果");
    excel_title.append("道路清洁");
    excel_title.append("噪声控制(昼间)");
    excel_title.append("噪声控制(夜间))");
    excel_title.append("厂界大气污染物浓度(可吸入颗粒物)");
    excel_title.append("厂界大气污染物浓度(臭度)");
    excel_title.append("厂界大气污染物浓度(NOx)");
    excel_title.append("厂界大气污染物浓度(SO2)");
    excel_title.append("厂界大气污染物浓度(HCl)");

    excel_title.append("车辆");
    excel_title.append("进出口门及时关闭，风幕开启");
    excel_title.append("臭气收集处理设备运行正常");
    excel_title.append("达标排放(氨NH3)");
    excel_title.append("达标排放(硫化氢)");
    excel_title.append("达标排放(臭度)");


    excel_title.append("垃圾卸料大厅运行安全操作监督");
    excel_title.append("稽核及监督安全管理制度");
    excel_title.append("定期检查操作票和工作票执行状况");
    excel_title.append("监督并要求运营方定期检查重要安全标志与设施有效性");
    excel_title.append("厂区工作进行巡查");
    excel_title.append("检查运营单位人员资质");



    //将数据对应的位置，存放到字典中
    data_map.insert("data_0", "A2");    //  第0个数据,日期

    data_map.insert("data_16", "C5");
    data_map.insert("data_17", "C6");
    data_map.insert("data_18", "C7");
    data_map.insert("data_20", "C8");
    data_map.insert("data_4", "C12");
    data_map.insert("data_2", "C13");
    data_map.insert("data_3", "C14");
    data_map.insert("data_6", "C19");
    data_map.insert("data_25", "C27");
    data_map.insert("data_11", "C28");
    data_map.insert("data_7", "C33");
    data_map.insert("data_120", "D36");
    data_map.insert("data_118", "D37");
    data_map.insert("data_119", "D38");
    data_map.insert("data_58", "D44");
    data_map.insert("data_66", "D47");
    data_map.insert("data_64", "D53");
    data_map.insert("data_43", "D56");
    data_map.insert("data_32", "D58");
    data_map.insert("data_45", "D60");
    data_map.insert("data_113", "B68");
    data_map.insert("data_114", "B69");
    data_map.insert("data_8", "B74");
    data_map.insert("data_9", "B75");
    data_map.insert("data_76", "B79");
    data_map.insert("data_75", "C79");
    data_map.insert("data_74", "D79");
    data_map.insert("data_77", "E79");
    data_map.insert("data_78", "F79");
    data_map.insert("data_124", "B80");
    data_map.insert("data_123", "C80");
    data_map.insert("data_122", "D80");
    data_map.insert("data_125", "E80");
    data_map.insert("data_126", "F80");
    data_map.insert("data_129", "C96");
    data_map.insert("data_130", "C97");
    data_map.insert("data_131", "C98");
    data_map.insert("data_132", "C99");
    data_map.insert("data_133", "C100");
    data_map.insert("data_134", "C101");
    data_map.insert("data_135", "C102");
    data_map.insert("data_136", "C103");

    //数据编号的最大值+1，第0个是日期
    //增加数据后要修改，遍历数据列表时会用到。
    data_number_max = 137;

    //界面设置
    Interface_config();

}

MainWindow::~MainWindow()
{
    delete ui;
}

// 导入数据按钮
// 点击导入数据，选择Excel文件，并将数据导入到下方列表中
void MainWindow::on_pushButton_clicked()
{

//    选择文件
    QString file_name;
    file_name= QFileDialog::getOpenFileName(this,tr("Open File"),"",tr("text(*.xls)"));
    ui->file_name_line->setText(file_name);

    if(file_name.isEmpty())
    {
        //没有选择文件，就直接返回
        qDebug() << "is empty";
        return;
    }

/*连接Excel的sheet*/
    // step1：连接控件
    QAxObject* excel = new QAxObject(this);

    bool status;
    status = excel->setControl("KET.Application");  // 连接Excel控件 这是 WPS 软件
//    status = excel->setControl("Excel.application");  // 连接Excel控件 这是 office 软件

    excel->dynamicCall("SetVisible (bool Visible)", "false"); // false:不显示窗体 true显示窗体
    excel->setProperty("DisplayAlerts", false);  // 不显示任何警告信息。如果为true, 那么关闭时会出现类似"文件已修改，是否保存"的提示


    // step2: 打开工作簿
    QAxObject* workbooks = excel->querySubObject("WorkBooks"); // 获取工作簿集合
    // 打开工作簿方式一：新建
//    workbooks->dynamicCall("Add"); // 新建一个工作簿
//    QAxObject* workbook = excel->querySubObject("ActiveWorkBook"); // 获取当前工作簿


    // 打开工作簿方式二：打开现成
//    QAxObject* workbook = workbooks->querySubObject("Open(const QString&)", "D:/workspace/project_qt/build-test1-Desktop_Qt_5_7_0_MinGW_32bit-Debug/项目中的已有数据.xls"); // 从控件lineEdit获取文件名
    QAxObject* workbook = workbooks->querySubObject("Open(const QString&)", file_name); // 从控件lineEdit获取文件名


    QAxObject * worksheets = workbook->querySubObject("WorkSheets");  //获取所有的工作表,
    int intCount = worksheets->property("Count").toInt();           //获取子表的个数,即 sheet 数
    qDebug() << "sheet 数" << intCount;

    // step3: 打开sheet
    QAxObject* worksheet = workbook->querySubObject("WorkSheets(int)", 1); // 获取工作表集合的工作表1， 即sheet1
//    QAxObject* worksheet = workbook->querySubObject("WorkSheets(int)", 2); // 获取工作表集合的工作表2， 即sheet2

    // step4: 获取行数，列数
    QAxObject* usedrange = worksheet->querySubObject("UsedRange"); // sheet范围
    int excel_intRowStart = usedrange->property("Row").toInt(); // 起始行数
    int excel_intColStart = usedrange->property("Column").toInt();  // 起始列数

    QAxObject *excel_rows, *excel_columns;
    excel_rows = usedrange->querySubObject("Rows");  // 行
    excel_columns = usedrange->querySubObject("Columns");  // 列

    int excel_intRow = excel_rows->property("Count").toInt(); // 行数
    int excel_intCol = excel_columns->property("Count").toInt();  // 列数

    qDebug() << "start" << excel_intRowStart << ',' << excel_intColStart;
    qDebug() << "matrix" << excel_intRow << ',' << excel_intCol;
    qDebug() << "data" << excel_rows;


//    // step5: 读和写
//    // 读方式一（坐标）：
//    int i = 2;  //第二行
//    int j = 1;  //第一列

//    QAxObject* cell = worksheet->querySubObject("Cells(int, int)", i, j);  //获单元格值

//    QString tmp = cell->dynamicCall("Value2()").toString();

//    qDebug() << i << j << tmp;


//    ui->tableWidget->item(0,0)->setText("temp");

//    // 读取Excel中的数据，当前共11列：
//    for(int i =1; i<=11; i++)
//    {
//        //数据在表格的第二行，第i列
//        QString tmp = worksheet->querySubObject("Cells(int, int)", 2, i)->dynamicCall("Value2()").toString();
//        qDebug() << i << ":" << tmp;


//        ui->tableWidget->item(0,i-1)->setText(tmp);
//    }


////    // 读方式二（行列名称）：
//    int i = 1;
//    QString X = "A" + QString::number(i + 1); //设置要操作的单元格，A1
////    QString X = "A1";
//    QAxObject* cellX = worksheet->querySubObject("Range(QVariant, QVariant)", X); //获取单元格
//    qDebug() << "A1:" << cellX->dynamicCall("Value2()").toString();

    //读取表格中的数据



    QAxObject* cellX1 = worksheet->querySubObject("Range(QVariant, QVariant)", "A2"); //获取单元格
    qDebug() << cellX1->dynamicCall("Value2()");

    QAxObject* cellX2 = worksheet->querySubObject("Range(QVariant, QVariant)", "B2"); //获取单元格
    qDebug() << cellX2->dynamicCall("Value2()").toString();




    data_list.clear();
    qDebug() << "data list length" << data_list.length();
    for(int i=0; i<data_number_max; i++)
    {
        QString data = "";
//        QString data_key = "data_" + QString::number(i+1);  //索引从1开始，即数据编号从1开始
        QString data_key = "data_" + QString::number(i);  //索引从0开始，数据编号从1开始，data_0 存放日期
        if(data_map.contains(data_key))
        {

            QMap<QString,QString>::iterator tmp = data_map.find(data_key); //找到特定的“键-值”对

            QString data_position = tmp.value();        // 获取键-值对中的值，即数据位置

            QAxObject* cellX = worksheet->querySubObject("Range(QVariant, QVariant)", data_position); //获取单元格
            data = cellX->dynamicCall("Value2()").toString();

//            qDebug() << data_key << ":" << data_position << ":" << data;
        }
        data_list.append(data);
//        qDebug() << data_list[i];
    }
    qDebug() << data_list[0];

//    for(int i=0; i<DATA_LENGTH; i++)
//    {
//        if(!data_list[i].isEmpty())
//        {
//            qDebug() << "data" << i+1 << ":" << data_list[i];
//        }
//    }


    display_data_from_list_to_editline();







//    // 写方式：
//    cellX->dynamicCall("SetValue(conts QVariant&)", 100); // 设置单元格的值


    // step6: 保存文件
    // 方式一：保存当前文件
//    workbook->dynamicCall("Save()");  //保存文件
    workbook->dynamicCall("Close(Boolean)", false);  //关闭文件

//    // 方式二：另存为
//    QString fileName = QFileDialog::getSaveFileName(this, tr("保存文件")," （注：指定路径）", tr("EXCEL(*.xlsx)"));
//    workbook->dynamicCall("SaveAs(const QString&)", QDir::toNativeSeparators(fileName)); //保存到filepath
//    // 注意一定要用QDir::toNativeSeparators, 将路径中的"/"转换为"\", 不然一定保存不了
//    workbook->dynamicCall("Close (Boolean)", false);  //关闭文件

}

//选择表格的一行时，将表格内容显示到编辑框
void MainWindow::on_tableWidget_itemSelectionChanged()
{
    //获取当前选中行的行号
    int currentrow = ui->tableWidget->currentRow();
    qDebug() << "current" << currentrow;
    if(currentrow < 0)
        return;

    //将选中的行中的数据，写入到编辑框中
//    ui->lineEdit_Waste_disposal->setText(ui->tableWidget->item(currentrow,0)->text());   //第1列
//    ui->lineEdit_Power_generation_1->setText(ui->tableWidget->item(currentrow,1)->text());   //第2列
//    ui->lineEdit_Power_generation_2->setText(ui->tableWidget->item(currentrow,2)->text());   //第3列
//    ui->lineEdit_Power_generation_all->setText(ui->tableWidget->item(currentrow,3)->text());   //第4列
//    ui->lineEdit_Running_time->setText(ui->tableWidget->item(currentrow,4)->text());   //第5列
//    ui->lineEdit_Electric_quantity_out_power_grid->setText(ui->tableWidget->item(currentrow,5)->text());   //第6列
//    ui->lineEdit_power_in_factory->setText(ui->tableWidget->item(currentrow,6)->text());   //第7列
//    ui->lineEdit_steam_1->setText(ui->tableWidget->item(currentrow,7)->text());   //第8列
//    ui->lineEdit_steam_2->setText(ui->tableWidget->item(currentrow,8)->text());   //第9列
//    ui->lineEdit_steam_3->setText(ui->tableWidget->item(currentrow,9)->text());   //第10列
//    ui->lineEdit_steam_all->setText(ui->tableWidget->item(currentrow,10)->text());   //第11列
}

//这个可以不用
void MainWindow::on_tableWidget_itemClicked(QTableWidgetItem *item)
{

}

//表格内容改变时，将选中的行的内容更新到编辑框
void MainWindow::on_tableWidget_itemChanged(QTableWidgetItem *item)
{
    //获取当前选中行的行号
    int currentrow = ui->tableWidget->currentRow();
    qDebug() << "current" << currentrow;
    if(currentrow < 0)
        return;

    //将选中的行中的数据，写入到编辑框中
//    ui->lineEdit_Waste_disposal->setText(ui->tableWidget->item(currentrow,0)->text());   //第1列
//    ui->lineEdit_Power_generation_1->setText(ui->tableWidget->item(currentrow,1)->text());   //第2列
//    ui->lineEdit_Power_generation_2->setText(ui->tableWidget->item(currentrow,2)->text());   //第3列
//    ui->lineEdit_Power_generation_all->setText(ui->tableWidget->item(currentrow,3)->text());   //第4列
//    ui->lineEdit_Running_time->setText(ui->tableWidget->item(currentrow,4)->text());   //第5列
//    ui->lineEdit_Electric_quantity_out_power_grid->setText(ui->tableWidget->item(currentrow,5)->text());   //第6列
//    ui->lineEdit_power_in_factory->setText(ui->tableWidget->item(currentrow,6)->text());   //第7列
//    ui->lineEdit_steam_1->setText(ui->tableWidget->item(currentrow,7)->text());   //第8列
//    ui->lineEdit_steam_2->setText(ui->tableWidget->item(currentrow,8)->text());   //第9列
//    ui->lineEdit_steam_3->setText(ui->tableWidget->item(currentrow,9)->text());   //第10列
//    ui->lineEdit_steam_all->setText(ui->tableWidget->item(currentrow,10)->text());   //第11列
}

//void MainWindow::on_lineEdit_Power_generation_2_editingFinished()
//{
//    //第3个编辑框，对应第2列的数据

//    //获取当前选中行的行号
//    int currentrow = ui->tableWidget->currentRow();
//    qDebug() << "current" << currentrow;
//    if(currentrow < 0)
//        return;

//    currentrow = 0; //只改变第一行的数据
//    ui->tableWidget->item(currentrow,2)->setText(ui->lineEdit_Power_generation_2->text());
//}

//void MainWindow::on_lineEdit_Power_generation_all_editingFinished()
//{
//    //第4个编辑框，对应第3列的数据

//    //获取当前选中行的行号
//    int currentrow = ui->tableWidget->currentRow();
//    qDebug() << "current" << currentrow;
//    if(currentrow < 0)
//        return;

//    currentrow = 0; //只改变第一行的数据
//    ui->tableWidget->item(currentrow,3)->setText(ui->lineEdit_Power_generation_all->text());
//}

//void MainWindow::on_lineEdit_steam_1_editingFinished()
//{
//    //第8个编辑框，对应第7列的数据

//    //获取当前选中行的行号
//    int currentrow = ui->tableWidget->currentRow();
//    qDebug() << "current" << currentrow;
//    if(currentrow < 0)
//        return;

//    currentrow = 0; //只改变第一行的数据
//    ui->tableWidget->item(currentrow,7)->setText(ui->lineEdit_steam_1->text());
//}

//void MainWindow::on_lineEdit_steam_2_editingFinished()
//{
//    //第9个编辑框，对应第8列的数据

//    //获取当前选中行的行号
//    int currentrow = ui->tableWidget->currentRow();
//    qDebug() << "current" << currentrow;
//    if(currentrow < 0)
//        return;

//    currentrow = 0; //只改变第一行的数据
//    ui->tableWidget->item(currentrow,8)->setText(ui->lineEdit_steam_2->text());
//}

//void MainWindow::on_lineEdit_steam_3_editingFinished()
//{
//    //第10个编辑框，对应第9列的数据

//    //获取当前选中行的行号
//    int currentrow = ui->tableWidget->currentRow();
//    qDebug() << "current" << currentrow;
//    if(currentrow < 0)
//        return;

//    currentrow = 0; //只改变第一行的数据
//    ui->tableWidget->item(currentrow,9)->setText(ui->lineEdit_steam_3->text());
//}

//void MainWindow::on_lineEdit_steam_all_editingFinished()
//{
//    //第11个编辑框，对应第10列的数据

//    //获取当前选中行的行号
//    int currentrow = ui->tableWidget->currentRow();
//    qDebug() << "current" << currentrow;
//    if(currentrow < 0)
//        return;

//    currentrow = 0; //只改变第一行的数据
//    ui->tableWidget->item(currentrow,10)->setText(ui->lineEdit_steam_all->text());
//}

//void MainWindow::on_lineEdit_Running_time_editingFinished()
//{
//    //第5个编辑框，对应第4列的数据

//    //获取当前选中行的行号
//    int currentrow = ui->tableWidget->currentRow();
//    qDebug() << "current" << currentrow;
//    if(currentrow < 0)
//        return;

//    currentrow = 0; //只改变第一行的数据
//    ui->tableWidget->item(currentrow,4)->setText(ui->lineEdit_Running_time->text());
//}

//void MainWindow::on_lineEdit_Electric_quantity_out_power_grid_editingFinished()
//{
//    //第6个编辑框，对应第5列的数据

//    //获取当前选中行的行号
//    int currentrow = ui->tableWidget->currentRow();
//    qDebug() << "current" << currentrow;
//    if(currentrow < 0)
//        return;

//    currentrow = 0; //只改变第一行的数据
//    ui->tableWidget->item(currentrow,5)->setText(ui->lineEdit_Electric_quantity_out_power_grid->text());
//}

//void MainWindow::on_lineEdit_power_in_factory_editingFinished()
//{
//    //第7个编辑框，对应第6列的数据

//    //获取当前选中行的行号
//    int currentrow = ui->tableWidget->currentRow();
//    qDebug() << "current" << currentrow;
//    if(currentrow < 0)
//        return;

//    currentrow = 0; //只改变第一行的数据
//    ui->tableWidget->item(currentrow,6)->setText(ui->lineEdit_power_in_factory->text());
//}

void MainWindow::on_pushButton_savedata_clicked()
{
    QList <int> data_Empty;
    for(int i=0; i<data_list.length(); i++)
    {
        if(data_list[i]=="")
        {
            data_Empty.append(i);
        }

    }
    if(!data_Empty.isEmpty())
    {
//        Incomplete_data * messagebox = new Incomplete_data()
        Incomplete_data *messagebox = new Incomplete_data();


        QString message;


        for(int i=0; i<data_Empty.length(); i++)
        {
            QString tmp = QString::number(data_Empty[i]+1)+":" + excel_title[i+1] + "\r\n";
            message.append(tmp);
        }

        //弹出对话框，提示数据不全
        messagebox->set_message(message);
        messagebox->show();

        //获取对话框返回值，1：确定，0：取消
        int a =messagebox->exec();
        qDebug() << "a" << a;

        if(a==0)
        {
            return;
        }
    }



//    获取Excel中的数据
    // step1：连接控件
    QAxObject* excel = new QAxObject(this);

    bool status;
    status = excel->setControl("KET.Application");  // 连接Excel控件 这是 WPS 软件
//    status = excel->setControl("Excel.application");  // 连接Excel控件 这是 office 软件

    excel->dynamicCall("SetVisible (bool Visible)", "false"); // false:不显示窗体 true显示窗体
    excel->setProperty("DisplayAlerts", false);  // 不显示任何警告信息。如果为true, 那么关闭时会出现类似"文件已修改，是否保存"的提示

    // step2: 打开工作簿
    QAxObject* workbooks = excel->querySubObject("WorkBooks"); // 获取工作簿集合
    // 打开工作簿方式一：新建
//    workbooks->dynamicCall("Add"); // 新建一个工作簿
//    QAxObject* workbook = excel->querySubObject("ActiveWorkBook"); // 获取当前工作簿


    qDebug() << "新建完成";
    // 打开工作簿方式二：打开现成
    QAxObject* workbook = workbooks->querySubObject("Open(const QString&)", "D:/data/save_data.xls"); // 从控件lineEdit获取文件名
//    QAxObject* workbook = workbooks->querySubObject("Open(const QString&)", file_name); // 从控件lineEdit获取文件名


    QAxObject * worksheets = workbook->querySubObject("WorkSheets");  //获取所有的工作表,
    int intCount = worksheets->property("Count").toInt();           //获取子表的个数,即 sheet 数
    qDebug() << "sheet 数" << intCount;

    // step3: 打开sheet
    QAxObject* worksheet = workbook->querySubObject("WorkSheets(int)", 1); // 获取工作表集合的工作表1， 即sheet1
//    QAxObject* worksheet = workbook->querySubObject("WorkSheets(int)", 2); // 获取工作表集合的工作表2， 即sheet2

    // step4: 获取行数，列数
    QAxObject* usedrange = worksheet->querySubObject("UsedRange"); // sheet范围
    int excel_intRowStart = usedrange->property("Row").toInt(); // 起始行数
    int excel_intColStart = usedrange->property("Column").toInt();  // 起始列数

    QAxObject *excel_rows, *excel_columns;
    excel_rows = usedrange->querySubObject("Rows");  // 行
    excel_columns = usedrange->querySubObject("Columns");  // 列

    int excel_intRow_count = excel_rows->property("Count").toInt(); // 行数
    int excel_intCol_count = excel_columns->property("Count").toInt();  // 列数

    qDebug() << "start" << excel_intRowStart << ',' << excel_intColStart;
    qDebug() << "matrix" << excel_intRow_count << ',' << excel_intCol_count;


    qDebug() << "length" <<excel_title.length();


    //只有一行，说明没数据
    if(excel_intRow_count<=1)
    {
        for(int i=0; i<excel_title.length(); i++)
        {
            //Excel的索引从1开始
            QAxObject* cell = worksheet->querySubObject("Cells(int, int)", 1, i+1);  //获单元格 索引从1开始

            cell->dynamicCall("SetValue(conts QVariant&)", excel_title[i]);//将表头写入到表格中的第一行
        }
    }

    //行数加1
    excel_intRow_count +=1;

    qDebug() << "excel_intRow_count" << excel_intRow_count;


//    //将日期存入第一列
//    日期已经存放到data_list的第0个位置。
//    QAxObject* cell = worksheet->querySubObject("Cells(int, int)", excel_intRow_count, 1);  //获单元格 索引从1开始
//    cell->dynamicCall("SetValue(conts QVariant&)", current_date);//将数据写入到表格中的最后一行

    for(int i =0; i<data_list.length(); i++)
    {
        QAxObject* cell = worksheet->querySubObject("Cells(int, int)", excel_intRow_count, i+1);  //获单元格 索引从1开始，第一列存入日期，数据从第二列开始存储

        cell->dynamicCall("SetValue(conts QVariant&)", data_list[i]);//将数据写入到表格中的最后一行
    }



//    //Excel的索引从1开始
//    QAxObject* cell = worksheet->querySubObject("Cells(int, int)", tmp_i, tmp_j);  //获单元格值

//    qDebug() << cell->dynamicCall("Value2()").toString();

//    cell->dynamicCall("SetValue(conts QVariant&)", 100);





    // 方式一：保存当前文件
    workbook->dynamicCall("Save()");  //保存文件
    workbook->dynamicCall("Close(Boolean)", false);  //关闭文件
}

void MainWindow::display_data_from_list_to_editline()
{
    ui->lineEdit_datetime->setText(data_list[0]);

    ui->lineEdit_data_1->setText(data_list[1]);
    ui->lineEdit_data_2->setText(data_list[2]);
    ui->lineEdit_data_3->setText(data_list[3]);
    ui->lineEdit_data_4->setText(data_list[4]);
    ui->lineEdit_data_5->setText(data_list[5]);
    ui->lineEdit_data_6->setText(data_list[6]);
    ui->lineEdit_data_7->setText(data_list[7]);
    ui->lineEdit_data_8->setText(data_list[8]);
    ui->lineEdit_data_9->setText(data_list[9]);
    ui->lineEdit_data_10->setText(data_list[10]);
    ui->lineEdit_data_11->setText(data_list[11]);

    ui->lineEdit_data_12->setText(data_list[12]);
    ui->lineEdit_data_13->setText(data_list[13]);
    ui->lineEdit_data_14->setText(data_list[14]);
    ui->lineEdit_data_15->setText(data_list[15]);
    ui->lineEdit_data_16->setText(data_list[16]);
    ui->lineEdit_data_17->setText(data_list[17]);
    ui->lineEdit_data_18->setText(data_list[18]);
    ui->lineEdit_data_19->setText(data_list[19]);
    ui->lineEdit_data_20->setText(data_list[20]);
    ui->lineEdit_data_21->setText(data_list[21]);
    ui->lineEdit_data_22->setText(data_list[22]);
    ui->lineEdit_data_23->setText(data_list[23]);
    ui->lineEdit_data_24->setText(data_list[24]);
    ui->lineEdit_data_25->setText(data_list[25]);
    ui->lineEdit_data_26->setText(data_list[26]);
    ui->lineEdit_data_27->setText(data_list[27]);
    ui->lineEdit_data_28->setText(data_list[28]);
    ui->lineEdit_data_29->setText(data_list[29]);
    ui->lineEdit_data_30->setText(data_list[30]);
    ui->lineEdit_data_31->setText(data_list[31]);
    ui->lineEdit_data_32->setText(data_list[32]);
    ui->lineEdit_data_33->setText(data_list[33]);
    ui->lineEdit_data_34->setText(data_list[34]);
    ui->lineEdit_data_35->setText(data_list[35]);
    ui->lineEdit_data_36->setText(data_list[36]);
    ui->lineEdit_data_37->setText(data_list[37]);
    ui->lineEdit_data_38->setText(data_list[38]);
    ui->lineEdit_data_39->setText(data_list[39]);
    ui->lineEdit_data_40->setText(data_list[40]);
    ui->lineEdit_data_41->setText(data_list[41]);
    ui->lineEdit_data_42->setText(data_list[42]);
    ui->lineEdit_data_43->setText(data_list[43]);
    ui->lineEdit_data_44->setText(data_list[44]);
    ui->lineEdit_data_45->setText(data_list[45]);
    ui->lineEdit_data_46->setText(data_list[46]);
    ui->lineEdit_data_47->setText(data_list[47]);
    ui->lineEdit_data_48->setText(data_list[48]);
    ui->lineEdit_data_49->setText(data_list[49]);
    ui->lineEdit_data_50->setText(data_list[50]);
    ui->lineEdit_data_51->setText(data_list[51]);
    ui->lineEdit_data_52->setText(data_list[52]);
    ui->lineEdit_data_53->setText(data_list[53]);
    ui->lineEdit_data_54->setText(data_list[54]);
    ui->lineEdit_data_55->setText(data_list[55]);
    ui->lineEdit_data_56->setText(data_list[56]);
    ui->lineEdit_data_57->setText(data_list[57]);
    ui->lineEdit_data_58->setText(data_list[58]);
    ui->lineEdit_data_59->setText(data_list[59]);
    ui->lineEdit_data_60->setText(data_list[60]);
    ui->lineEdit_data_61->setText(data_list[61]);
    ui->lineEdit_data_62->setText(data_list[62]);
    ui->lineEdit_data_63->setText(data_list[63]);
    ui->lineEdit_data_64->setText(data_list[64]);
    ui->lineEdit_data_65->setText(data_list[65]);
    ui->lineEdit_data_66->setText(data_list[66]);
    ui->lineEdit_data_67->setText(data_list[67]);
    ui->lineEdit_data_68->setText(data_list[68]);
    ui->lineEdit_data_69->setText(data_list[69]);
    ui->lineEdit_data_70->setText(data_list[70]);
    ui->lineEdit_data_71->setText(data_list[71]);
    ui->lineEdit_data_72->setText(data_list[72]);
    ui->lineEdit_data_73->setText(data_list[73]);
    ui->lineEdit_data_74->setText(data_list[74]);
    ui->lineEdit_data_75->setText(data_list[75]);
    ui->lineEdit_data_76->setText(data_list[76]);
    ui->lineEdit_data_77->setText(data_list[77]);
    ui->lineEdit_data_78->setText(data_list[78]);
    ui->lineEdit_data_79->setText(data_list[79]);
    ui->lineEdit_data_80->setText(data_list[80]);
    ui->lineEdit_data_81->setText(data_list[81]);
    ui->lineEdit_data_82->setText(data_list[82]);
    ui->lineEdit_data_83->setText(data_list[83]);
    ui->lineEdit_data_84->setText(data_list[84]);
    ui->lineEdit_data_85->setText(data_list[85]);
    ui->lineEdit_data_86->setText(data_list[86]);
    ui->lineEdit_data_87->setText(data_list[87]);
    ui->lineEdit_data_88->setText(data_list[88]);
    ui->lineEdit_data_89->setText(data_list[89]);
    ui->lineEdit_data_90->setText(data_list[90]);
    ui->lineEdit_data_91->setText(data_list[91]);
    ui->lineEdit_data_92->setText(data_list[92]);
    ui->lineEdit_data_93->setText(data_list[93]);
    ui->lineEdit_data_94->setText(data_list[94]);
    ui->lineEdit_data_95->setText(data_list[95]);
    ui->lineEdit_data_96->setText(data_list[96]);
    ui->lineEdit_data_97->setText(data_list[97]);
    ui->lineEdit_data_98->setText(data_list[98]);
    ui->lineEdit_data_99->setText(data_list[99]);
    ui->lineEdit_data_100->setText(data_list[100]);
    ui->lineEdit_data_101->setText(data_list[101]);
    ui->lineEdit_data_102->setText(data_list[102]);
    ui->lineEdit_data_103->setText(data_list[103]);
    ui->lineEdit_data_104->setText(data_list[104]);
    ui->lineEdit_data_105->setText(data_list[105]);
    ui->lineEdit_data_106->setText(data_list[106]);
    ui->lineEdit_data_107->setText(data_list[107]);
    ui->lineEdit_data_108->setText(data_list[108]);
    ui->lineEdit_data_109->setText(data_list[109]);
    ui->lineEdit_data_110->setText(data_list[110]);
    ui->lineEdit_data_111->setText(data_list[111]);
    ui->lineEdit_data_112->setText(data_list[112]);
    ui->lineEdit_data_113->setText(data_list[113]);
    ui->lineEdit_data_114->setText(data_list[114]);
    ui->lineEdit_data_115->setText(data_list[115]);
    ui->lineEdit_data_116->setText(data_list[116]);
    ui->lineEdit_data_117->setText(data_list[117]);
    ui->lineEdit_data_118->setText(data_list[118]);
    ui->lineEdit_data_119->setText(data_list[119]);
    ui->lineEdit_data_120->setText(data_list[120]);
    ui->lineEdit_data_121->setText(data_list[121]);
    ui->lineEdit_data_122->setText(data_list[122]);
    ui->lineEdit_data_123->setText(data_list[123]);
    ui->lineEdit_data_124->setText(data_list[124]);
    ui->lineEdit_data_125->setText(data_list[125]);
    ui->lineEdit_data_126->setText(data_list[126]);
    ui->lineEdit_data_127->setText(data_list[127]);
    ui->lineEdit_data_128->setText(data_list[128]);
    ui->lineEdit_data_129->setText(data_list[129]);
    ui->lineEdit_data_130->setText(data_list[130]);
    ui->lineEdit_data_131->setText(data_list[131]);
    ui->lineEdit_data_132->setText(data_list[132]);
    ui->lineEdit_data_133->setText(data_list[133]);
    ui->lineEdit_data_134->setText(data_list[134]);
    ui->lineEdit_data_135->setText(data_list[135]);
    ui->lineEdit_data_136->setText(data_list[136]);

}


void MainWindow::updata_from_editline_to_list()
{
    data_list[0] = ui->lineEdit_datetime->text();
    
    data_list[1] = ui->lineEdit_data_1->text();
    data_list[2] = ui->lineEdit_data_2->text();
    data_list[3] = ui->lineEdit_data_3->text();
    data_list[4] = ui->lineEdit_data_4->text();
    data_list[5] = ui->lineEdit_data_5->text();
    data_list[6] = ui->lineEdit_data_6->text();
    data_list[7] = ui->lineEdit_data_7->text();
    data_list[8] = ui->lineEdit_data_8->text();
    data_list[9] = ui->lineEdit_data_9->text();
    data_list[10] = ui->lineEdit_data_10->text();
    data_list[11] = ui->lineEdit_data_11->text();

    data_list[12] = ui->lineEdit_data_12->text();
    data_list[13] = ui->lineEdit_data_13->text();
    data_list[14] = ui->lineEdit_data_14->text();
    data_list[15] = ui->lineEdit_data_15->text();
    data_list[16] = ui->lineEdit_data_16->text();
    data_list[17] = ui->lineEdit_data_17->text();
    data_list[18] = ui->lineEdit_data_18->text();
    data_list[19] = ui->lineEdit_data_19->text();
    data_list[20] = ui->lineEdit_data_20->text();
    data_list[21] = ui->lineEdit_data_21->text();
    data_list[22] = ui->lineEdit_data_22->text();
    data_list[23] = ui->lineEdit_data_23->text();
    data_list[24] = ui->lineEdit_data_24->text();
    data_list[25] = ui->lineEdit_data_25->text();
    data_list[26] = ui->lineEdit_data_26->text();
    data_list[27] = ui->lineEdit_data_27->text();
    data_list[28] = ui->lineEdit_data_28->text();
    data_list[29] = ui->lineEdit_data_29->text();
    data_list[30] = ui->lineEdit_data_30->text();
    data_list[31] = ui->lineEdit_data_31->text();
    data_list[32] = ui->lineEdit_data_32->text();
    data_list[33] = ui->lineEdit_data_33->text();
    data_list[34] = ui->lineEdit_data_34->text();
    data_list[35] = ui->lineEdit_data_35->text();
    data_list[36] = ui->lineEdit_data_36->text();
    data_list[37] = ui->lineEdit_data_37->text();
    data_list[38] = ui->lineEdit_data_38->text();
    data_list[39] = ui->lineEdit_data_39->text();
    data_list[40] = ui->lineEdit_data_40->text();
    data_list[41] = ui->lineEdit_data_41->text();
    data_list[42] = ui->lineEdit_data_42->text();
    data_list[43] = ui->lineEdit_data_43->text();
    data_list[44] = ui->lineEdit_data_44->text();
    data_list[45] = ui->lineEdit_data_45->text();
    data_list[46] = ui->lineEdit_data_46->text();
    data_list[47] = ui->lineEdit_data_47->text();
    data_list[48] = ui->lineEdit_data_48->text();
    data_list[49] = ui->lineEdit_data_49->text();
    data_list[50] = ui->lineEdit_data_50->text();
    data_list[51] = ui->lineEdit_data_51->text();
    data_list[52] = ui->lineEdit_data_52->text();
    data_list[53] = ui->lineEdit_data_53->text();
    data_list[54] = ui->lineEdit_data_54->text();
    data_list[55] = ui->lineEdit_data_55->text();
    data_list[56] = ui->lineEdit_data_56->text();
    data_list[57] = ui->lineEdit_data_57->text();
    data_list[58] = ui->lineEdit_data_58->text();
    data_list[59] = ui->lineEdit_data_59->text();
    data_list[60] = ui->lineEdit_data_60->text();
    data_list[61] = ui->lineEdit_data_61->text();
    data_list[62] = ui->lineEdit_data_62->text();
    data_list[63] = ui->lineEdit_data_63->text();
    data_list[64] = ui->lineEdit_data_64->text();
    data_list[65] = ui->lineEdit_data_65->text();
    data_list[66] = ui->lineEdit_data_66->text();
    data_list[67] = ui->lineEdit_data_67->text();
    data_list[68] = ui->lineEdit_data_68->text();
    data_list[69] = ui->lineEdit_data_69->text();
    data_list[70] = ui->lineEdit_data_70->text();
    data_list[71] = ui->lineEdit_data_71->text();
    data_list[72] = ui->lineEdit_data_72->text();
    data_list[73] = ui->lineEdit_data_73->text();
    data_list[74] = ui->lineEdit_data_74->text();
    data_list[75] = ui->lineEdit_data_75->text();
    data_list[76] = ui->lineEdit_data_76->text();
    data_list[77] = ui->lineEdit_data_77->text();
    data_list[78] = ui->lineEdit_data_78->text();
    data_list[79] = ui->lineEdit_data_79->text();
    data_list[80] = ui->lineEdit_data_80->text();
    data_list[81] = ui->lineEdit_data_81->text();
    data_list[82] = ui->lineEdit_data_82->text();
    data_list[83] = ui->lineEdit_data_83->text();
    data_list[84] = ui->lineEdit_data_84->text();
    data_list[85] = ui->lineEdit_data_85->text();
    data_list[86] = ui->lineEdit_data_86->text();
    data_list[87] = ui->lineEdit_data_87->text();
    data_list[88] = ui->lineEdit_data_88->text();
    data_list[89] = ui->lineEdit_data_89->text();
    data_list[90] = ui->lineEdit_data_90->text();
    data_list[91] = ui->lineEdit_data_91->text();
    data_list[92] = ui->lineEdit_data_92->text();
    data_list[93] = ui->lineEdit_data_93->text();
    data_list[94] = ui->lineEdit_data_94->text();
    data_list[95] = ui->lineEdit_data_95->text();
    data_list[96] = ui->lineEdit_data_96->text();
    data_list[97] = ui->lineEdit_data_97->text();
    data_list[98] = ui->lineEdit_data_98->text();
    data_list[99] = ui->lineEdit_data_99->text();
    data_list[100] = ui->lineEdit_data_100->text();
    data_list[101] = ui->lineEdit_data_101->text();
    data_list[102] = ui->lineEdit_data_102->text();
    data_list[103] = ui->lineEdit_data_103->text();
    data_list[104] = ui->lineEdit_data_104->text();
    data_list[105] = ui->lineEdit_data_105->text();
    data_list[106] = ui->lineEdit_data_106->text();
    data_list[107] = ui->lineEdit_data_107->text();
    data_list[108] = ui->lineEdit_data_108->text();
    data_list[109] = ui->lineEdit_data_109->text();
    data_list[110] = ui->lineEdit_data_110->text();
    data_list[111] = ui->lineEdit_data_111->text();
    data_list[112] = ui->lineEdit_data_112->text();
    data_list[113] = ui->lineEdit_data_113->text();
    data_list[114] = ui->lineEdit_data_114->text();
    data_list[115] = ui->lineEdit_data_115->text();
    data_list[116] = ui->lineEdit_data_116->text();
    data_list[117] = ui->lineEdit_data_117->text();
    data_list[118] = ui->lineEdit_data_118->text();
    data_list[119] = ui->lineEdit_data_119->text();
    data_list[120] = ui->lineEdit_data_120->text();
    data_list[121] = ui->lineEdit_data_121->text();
    data_list[122] = ui->lineEdit_data_122->text();
    data_list[123] = ui->lineEdit_data_123->text();
    data_list[124] = ui->lineEdit_data_124->text();
    data_list[125] = ui->lineEdit_data_125->text();
    data_list[126] = ui->lineEdit_data_126->text();
    data_list[127] = ui->lineEdit_data_127->text();
    data_list[128] = ui->lineEdit_data_128->text();
    data_list[129] = ui->lineEdit_data_129->text();
    data_list[130] = ui->lineEdit_data_130->text();
    data_list[131] = ui->lineEdit_data_131->text();
    data_list[132] = ui->lineEdit_data_132->text();
    data_list[133] = ui->lineEdit_data_133->text();
    data_list[134] = ui->lineEdit_data_134->text();
    data_list[135] = ui->lineEdit_data_135->text();
    data_list[136] = ui->lineEdit_data_136->text();

//    for(int i =0; i< data_list.length(); i++)
//    {
//        qDebug() << i << ":" << data_list[i];
//    }
}


//界面上的编辑框改变时，执行的动作
void MainWindow::change_data_from_editline()
{
    updata_from_editline_to_list();
}

void MainWindow::Interface_config()
{
    //获取日期，设置日期编辑框
    QDateTime current_date_time =QDateTime::currentDateTime();
    current_date =current_date_time.toString("yyyy-MM-dd");
    ui->lineEdit_datetime->setText(current_date);


    /*表格样式设置*/

    //运行监管，第1个表格设置
    ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    // 设置单元格拉伸显示，适应窗口大小
    ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
    // 设置点击选中一整行
    //ui->tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
    // 禁止编辑


    //运行监管，第2个表格设置
    ui->tableWidget_1_2->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    // 设置单元格拉伸显示，适应窗口大小
    ui->tableWidget_1_2->setSelectionBehavior(QAbstractItemView::SelectRows);
    // 设置点击选中一整行
    //ui->tableWidget_1_2->setEditTriggers(QAbstractItemView::NoEditTriggers);
    // 禁止编辑


    //运行监管，第3个表格设置
    ui->tableWidget_1_3->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    // 设置单元格拉伸显示，适应窗口大小
    ui->tableWidget_1_3->setSelectionBehavior(QAbstractItemView::SelectRows);
    // 设置点击选中一整行
    //ui->tableWidget_1_3->setEditTriggers(QAbstractItemView::NoEditTriggers);
    // 禁止编辑


    //运行监管，第4个表格设置
    ui->tableWidget_1_4->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    // 设置单元格拉伸显示，适应窗口大小
    ui->tableWidget_1_4->setSelectionBehavior(QAbstractItemView::SelectRows);
    // 设置点击选中一整行
    //ui->tableWidget_1_4->setEditTriggers(QAbstractItemView::NoEditTriggers);
    // 禁止编辑


    //环保监管，第1个表格设置
    ui->tableWidget_2_1->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    // 设置单元格拉伸显示，适应窗口大小
    ui->tableWidget_2_1->setSelectionBehavior(QAbstractItemView::SelectRows);
    // 设置点击选中一整行
    //ui->tableWidget_2_1->setEditTriggers(QAbstractItemView::NoEditTriggers);
    // 禁止编辑


    //环保监管，第2个表格设置
    ui->tableWidget_2_2->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    // 设置单元格拉伸显示，适应窗口大小
    ui->tableWidget_2_2->setSelectionBehavior(QAbstractItemView::SelectRows);
    // 设置点击选中一整行
    //ui->tableWidget_2_2->setEditTriggers(QAbstractItemView::NoEditTriggers);
    // 禁止编辑


    //环保监管，第3个表格设置
    ui->tableWidget_2_3->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    // 设置单元格拉伸显示，适应窗口大小
    ui->tableWidget_2_3->setSelectionBehavior(QAbstractItemView::SelectRows);
    // 设置点击选中一整行
    //ui->tableWidget_2_3->setEditTriggers(QAbstractItemView::NoEditTriggers);
    // 禁止编辑


    //环保监管，第4个表格设置
    ui->tableWidget_2_4->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    // 设置单元格拉伸显示，适应窗口大小
    ui->tableWidget_2_4->setSelectionBehavior(QAbstractItemView::SelectRows);
    // 设置点击选中一整行
    //ui->tableWidget_2_4->setEditTriggers(QAbstractItemView::NoEditTriggers);
    // 禁止编辑


    //环保监管，第5个表格设置
    ui->tableWidget_2_5->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    // 设置单元格拉伸显示，适应窗口大小
    ui->tableWidget_2_5->setSelectionBehavior(QAbstractItemView::SelectRows);
    // 设置点击选中一整行
    //ui->tableWidget_2_5->setEditTriggers(QAbstractItemView::NoEditTriggers);
    // 禁止编辑


    //环保监管，第6个表格设置
    ui->tableWidget_2_6->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    // 设置单元格拉伸显示，适应窗口大小
    ui->tableWidget_2_6->setSelectionBehavior(QAbstractItemView::SelectRows);
    // 设置点击选中一整行
    //ui->tableWidget_2_6->setEditTriggers(QAbstractItemView::NoEditTriggers);
    // 禁止编辑


    //环保监管，第7个表格设置
    ui->tableWidget_2_7->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    // 设置单元格拉伸显示，适应窗口大小
    ui->tableWidget_2_7->setSelectionBehavior(QAbstractItemView::SelectRows);
    // 设置点击选中一整行
    //ui->tableWidget_2_7->setEditTriggers(QAbstractItemView::NoEditTriggers);
    // 禁止编辑


    //环保监管，第8个表格设置
    ui->tableWidget_2_8->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    // 设置单元格拉伸显示，适应窗口大小
    ui->tableWidget_2_8->setSelectionBehavior(QAbstractItemView::SelectRows);
    // 设置点击选中一整行
    //ui->tableWidget_2_8->setEditTriggers(QAbstractItemView::NoEditTriggers);
    // 禁止编辑


    //安全监管，第1个表格设置
    ui->tableWidget_3_1->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    // 设置单元格拉伸显示，适应窗口大小
    ui->tableWidget_3_1->setSelectionBehavior(QAbstractItemView::SelectRows);
    // 设置点击选中一整行
    //ui->tableWidget_3_1->setEditTriggers(QAbstractItemView::NoEditTriggers);
    // 禁止编辑
}

//初始化函数
void MainWindow::init()
{

    //将数据列表初始化，获得一个长度为最大数据编号值的数据列表
    for(int i=0; i<data_number_max; i++)
    {
        data_list.append("");
    }

//    lineEdit_Waste_disposal
//    Power_generation_1
//    lineEdit_Power_generation_2
//    lineEdit_Power_generation_all
//    lineEdit_Running_time
//    lineEdit_Electric_quantity_out_power_grid
//    lineEdit_power_in_factory

//    lineEdit_steam_1
//    lineEdit_steam_2
//    lineEdit_steam_3
//    lineEdit_steam_all

    //连接编辑框和槽 (数据修改函数)
    connect(ui->lineEdit_data_1,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_2,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_3,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_4,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_5,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_6,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_7,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_8,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_9,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_10,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_11,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));

    connect(ui->lineEdit_data_12,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_13,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_14,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_15,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_16,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_17,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_18,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_19,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_20,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_21,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_22,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_23,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_24,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_25,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_26,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_27,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_28,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_29,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_30,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_31,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_32,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_33,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_34,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_35,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_36,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_37,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_38,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_39,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_40,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_41,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_42,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_43,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_44,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_45,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_46,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_47,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_48,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_49,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_50,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_51,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_52,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_53,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_54,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_55,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_56,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_57,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_58,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_59,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_60,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_61,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_62,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_63,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_64,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_65,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_66,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_67,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_68,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_69,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_70,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_71,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_72,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_73,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_74,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_75,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_76,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_77,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_78,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_79,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_80,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_81,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_82,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_83,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_84,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_85,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_86,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_87,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_88,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_89,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_90,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_91,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_92,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_93,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_94,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_95,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_96,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_97,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_98,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_99,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_100,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_101,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_102,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_103,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_104,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_105,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_106,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_107,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_108,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_109,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_110,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_111,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_112,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_113,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_114,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_115,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_116,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_117,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_118,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_119,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_120,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_121,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_122,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_123,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_124,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_125,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_126,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_127,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_128,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_129,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_130,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_131,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_132,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_133,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_134,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_135,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
    connect(ui->lineEdit_data_136,SIGNAL(editingFinished()),this,SLOT(change_data_from_editline()));
}
